package com.dhnsoft.每天一道力扣;

/**
 * @author dhn
 * @version 1.0
 * @date 2023-10-18 10:12
 * @Desc
 */
public class day01_704_二分查找 {
    public static void main(String[] args) {
        int[] nums = {2};
        int search = search(nums, 2);
        System.out.println(search);
    }
    public static int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length;
        return binarySearch(nums,left,right,target);
    }

    public static int binarySearch(int[] nums,int left,int right,int target){
        if(left>right){
            return -1;
        }
        int mid = (left+right)/2;
        if(mid==6||mid>=nums.length||mid<0){
            return -1;
        }
        if(target>nums[mid]){
            return binarySearch(nums,mid+1,right,target);
        } else if (target<nums[mid]) {

            return binarySearch(nums,left,mid-1,target);
        }
        else {
            return mid;
        }
    }
}
